/**
 * 存储源
 * @author luguoxiang
 * @date 2024-03-01
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { BaseEntity, IConfigSchema } from '@/soar';
import { basePath } from './api';
import { MenuComponent } from '@/types/interface';

export type StorageSource = BaseEntity;

const fieldList: IConfigSchema<StorageSource>[] = [
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'path',
    label: '路径',
    dataType: 'string',
    form: {
      rules: true,
      slots: 'path',
    },
  },
  {
    field: 'content',
    label: '内容(el表达式)',
    dataType: 'string',
  },
  {
    field: 'type',
    label: '类型',
    dataType: 'dict',
    params: 'LogTypeEnum',
    table: {
      width: 100,
    },
    form: {
      rules: true,
    },
  },
  {
    field: 'argsMode',
    label: '入参记录模式',
    dataType: 'dict',
    params: 'LogArgsModeEnum',
    table: {
      width: 120,
    },
    form: {
      rules: true,
      componentProps: {
        component: 't-radio-group',
      },
    },
  },
  {
    field: 'argsEl',
    label: '入参el表达式',
    dataType: 'string',
    table: false,
    search: false,
    form: {
      rules: true,
      vif({ data }) {
        return data.argsMode === 1;
      },
    },
  },
  {
    field: 'argsIndex',
    label: '入参索引',
    dataType: 'number',
    table: false,
    search: false,
    form: {
      rules: true,
      vif({ data }) {
        return data.argsMode === 2;
      },
    },
  },
  {
    field: 'resultMode',
    label: '出参记录模式',
    dataType: 'dict',
    params: 'LogResultModeEnum',
    table: {
      width: 120,
    },
    form: {
      rules: true,
      componentProps: {
        component: 't-radio-group',
      },
    },
  },
  {
    field: 'resultEl',
    label: '出参el表达式',
    dataType: 'string',
    table: false,
    search: false,
    form: {
      rules: true,
      vif({ data }) {
        return data.resultMode === 1;
      },
    },
  },
  {
    field: 'errorMode',
    label: '错误记录记录模式',
    dataType: 'dict',
    params: 'LogErrorModeEnum',
    table: {
      width: 140,
    },
    form: {
      rules: true,
      componentProps: {
        component: 't-radio-group',
      },
    },
  },
  {
    field: 'status',
    label: '状态',
    dataType: 'dict',
    params: 'LogConfigStatusEnum',
    table: {
      width: 100,
    },
    form: {
      rules: true,
      componentProps: {
        component: 't-radio-group',
      },
    },
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '日志配置',
    component: () => import('./List.vue'),
    sort: 40,
    keepalive: true,
    icon: 'usb',
    permits: [`GET${basePath}/query`, `GET${basePath}/getMode`],
    elements: [
      { title: '新增', code: 'create', permits: [`POST${basePath}/create`] },
      {
        title: '更新',
        code: 'update',
        permits: [`POST${basePath}/update`, `GET${basePath}/detail`],
      },
      { title: '删除', code: 'remove', permits: [`POST${basePath}/remove`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
      { title: '导入', code: 'import', permits: [`POST${basePath}/import`] },
      { title: '导出', code: 'export', permits: [`GET${basePath}/export`] },
    ],
  },
];
